<!--
 * @Author: lmk
 * @Date: 2022-04-15 22:27:06
 * @LastEditTime: 2022-07-01 11:39:45
 * @LastEditors: lmk
 * @Description: 
-->
<template>
  <pageView pageName="activity" @getSearchValue="getSearchValue"  bannerImage="/img/banner/activitybanner.png">
    <!-- <div class="tab-view flex justify-center">
      <p :class="{active:state.tabIndex===0}" @click="changeIndex(0)">演出信息</p>
      <p :class="{active:state.tabIndex===1}" @click="changeIndex(1)">往期精彩</p>
    </div> -->
    <div class="content-view">
      <swiper
        class="swiper-container"
        :modules="modules"
        :pagination="{
          el: '.pagination',
          clickable: true
        }"
        @slideChange='onSlideChange'
        :virtual="true"
      >
        <swiper-slide
          v-for="(slideContent, index) in state.slides"
          :key="index"
          :virtualIndex="index">
            <div class="flex items-center slide-box" @click="detail(item)"
            v-for="(item, index) in slideContent" :key="index">
              <img :src="item.activitiFiguerImage" alt="" class="item-image flex-1">
              <div class="flex-1 silde-content">
                <p class="item-title">{{isZh ? item.activityName : item.activityNameEnglish}}</p>
                <img src="/img/activity/a-line.png" alt="">
                <div>
                  <p class="item-desc line-clamp-4">
                    {{isZh ? getElementText(item.activityDesc) : getElementText(item.activityDescEnglish)}}
                  </p>
                  <div class="line"></div>
                  <div class="flex address">
                    <p>{{item.activityShowTime}}</p>
                    <p>{{$t('activity.address')}}：{{isZh ? item.activityAddress : item.activityAddressEnglish}}</p>
                  </div>
                </div>
              </div>
            </div>
          </swiper-slide>
      </swiper>
      <div class="pagination"></div>
    </div>
  </pageView>
</template>

<script>
import pageView from '@/components/pageView'
import { Pagination,Virtual } from 'swiper';
import { Swiper, SwiperSlide } from "swiper/vue/swiper-vue";

import "swiper/swiper-bundle.css";
import { reactive, ref } from '@vue/reactivity';
import { pageWebsiteActivity } from '@/api/api';
import { useIsZh } from '@/utils/useIsZh';
import { useRouter } from 'vue-router';
import { getElementText } from '@/utils';
export default {
  data() {
    return {
      tabIndex: 0
    }
  },
  setup() {
    const {isZh} = useIsZh()
    const activeIndex = ref(0)
    // 获取当月数据
    const state = reactive({
      tabIndex:0,
      slides:[],
      current:1,
      activityName:''
    })
    // 监听index变化
    const onSlideChange = (swiper) => {
      state.current = swiper.activeIndex + 1;
      if(!state.slides[state.current - 1]){
        getList()
      }
    };
    //切换tab
    const changeIndex = (index) => {
      state.slides = [];
      state.current = 1;
      state.tabIndex = index 
      getList()
    }
    // 获取列表
    const getList = ()=>{
      pageWebsiteActivity({
        size:3,
        type:3,
        current:state.current,
        activityName:state.activityName
      }).then(res=>{
        if(state.slides.length === 0) state.slides = new Array(res.pages);
        if(state.slides.length>0){
          state.slides[state.current - 1] = res.records
        }
      })
    }
    getList()
    // 获取搜索条件
    const getSearchValue = (value) => {
      state.current = 1;
      state.activityName = value
      getList()
    }
    const router = useRouter()
    // 跳转详情
    const detail = item=>{
      router.push(`/activityDetail/${item.activityId}`)
    }
    return {
      onSlideChange,
      activeIndex,
      changeIndex,
      state,
      getSearchValue,
      isZh,
      detail,
      getElementText,
      modules:[Pagination,Virtual]
    };
  },
  components: {
    pageView,
    Swiper,
    SwiperSlide,
  }
}
</script>

<style lang="scss" scoped>

@media screen and (min-width: 1400px) {
  .tab-view{
    font-size: 24px;
    p{
      margin: 0 30px;
      padding-bottom: 12px;
      &.active{
        &::after{
          width: 60px;
          height: 4px;
          margin-left: -30px;
        }
      }
    }
  }
  .content-view{
    line-height: 1;
    margin-top: 40px;
    .slide-box{
      cursor: pointer;
      &:nth-child(even){
        flex-direction: row-reverse;
      }
    }
    .item{
      &-image{
        height: 358px;
        width: 518px;
      }
      &-title{
        font-size: 24px;
        margin-bottom: 30px;
        margin-left: 80px;
      }
      &-desc{
        font-size: 14px;
        margin-left: 80px;
        line-height: 30px;
        margin-right: 86px;
        margin-top: 30px;
      }
    }
    .line{
      margin-bottom: 20px;
      margin-top: 13px;
      margin-left: 80px;
    }
    .address{
      font-weight: bold;
      color: #666666;
      margin-left: 80px;
    }
  }
}
@media screen and (max-width: 1401px) {
  .tab-view{
    font-size: 18px;
    p{
      margin: 0 10px;
      padding-bottom: 6px;
      &.active{
        &::after{
          width: 30px;
          height: 2px;
          margin-left: -15px;
        }
      }
    }
  }

  .content-view{
    margin-top: 10px;
    .slide-box{
      display: block;
    }
    .silde-content{
      padding:50px 10px 50px;
    }
    .item{
      &-image{
        width: 100%;
        height: calc((100vw - 60px) * 0.55);
      }
      &-title{
        font-size: 12px;
        margin-bottom: 10px;
      }
      &-desc{
        font-size: 7px;
        margin-top: 5px;
        line-height: 20px;
      }
    }
    .line{
      margin:3px 0 10px;
    }
    .address{
      font-size: 7px;
      p{
        &:first-child{
          color: #999;
        }
      }
    }
  }
}
.tab-view{
  font-weight: 400;
  color: #FFFFFF;
  p{
    position: relative;
    cursor: pointer;
    &.active{
      color: $activeTxt;
      &::after{
        content: '';
        position: absolute;
        background: $activeTxt;
        bottom: 0;
        left: 50%;
      }
    }
  }
}
.content-view{
  .item{
    &-image{
      display: block;
      object-fit: cover;
    }
    &-title{
      font-weight: bold;
      color: #202020;
    }
    &-desc{
      font-weight: bold;
      color: #666666;
    }
  }
  .line{
    width: 20px;
    height: 4px;
    background: $activeTxt;
  }
  .address{
    font-weight: bold;
    color: #666666;
    p{
      &:last-child{
        margin-left: 14px;
      }
    }
  }
}
.swiper-container{
  background: #FFFAF5;
}
</style>